home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / syntax / c.vim < prev    next >
Encoding:
Text File  |  1998-03-31  |  5.4 KB  |  137 lines

  1. " Vim syntax file
  2. " Language:    C
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    1998 March 31
  5.  
  6. " Remove any old syntax stuff hanging around
  7. syn clear
  8.  
  9. " A bunch of useful C keywords
  10. syn keyword cStatement        goto break return continue asm
  11. syn keyword cLabel        case default
  12. syn keyword cConditional    if else switch
  13. syn keyword cRepeat        while for do
  14.  
  15. syn keyword cTodo contained    TODO FIXME XXX
  16.  
  17. " String and Character constants
  18. " Highlight special characters (those which have a backslash) differently
  19. syn match cSpecial contained    "\\[0-7][0-7][0-7]\=\|\\."
  20. syn region cString        start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
  21. syn match cCharacter        "'[^\\]'"
  22. syn match cSpecialCharacter    "'\\.'"
  23. syn match cSpecialCharacter    "'\\[0-7][0-7]'"
  24. syn match cSpecialCharacter    "'\\[0-7][0-7][0-7]'"
  25.  
  26. "catch errors caused by wrong parenthesis
  27. syn region cParen        transparent start='(' end=')' contains=ALLBUT,cParenError,cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
  28. syn match cParenError        ")"
  29. syn match cInParen contained    "[{}]"
  30.  
  31. "integer number, or floating point number without a dot and with "f".
  32. syn case ignore
  33. syn match cNumber        "\<[0-9]\+\(u\=l\=\|lu\|f\)\>"
  34. "floating point number, with dot, optional exponent
  35. syn match cFloat        "\<[0-9]\+\.[0-9]*\(e[-+]\=[0-9]\+\)\=[fl]\=\>"
  36. "floating point number, starting with a dot, optional exponent
  37. syn match cFloat        "\.[0-9]\+\(e[-+]\=[0-9]\+\)\=[fl]\=\>"
  38. "floating point number, without dot, with exponent
  39. syn match cFloat        "\<[0-9]\+e[-+]\=[0-9]\+[fl]\=\>"
  40. "hex number
  41. syn match cNumber        "\<0x[0-9a-f]\+\(u\=l\=\|lu\)\>"
  42. "syn match cIdentifier    "\<[a-z_][a-z0-9_]*\>"
  43. syn case match
  44. " flag an octal number with wrong digits
  45. syn match cOctalError        "\<0[0-7]*[89]"
  46.  
  47. if exists("c_comment_strings")
  48.   " A comment can contain cString, cCharacter and cNumber.
  49.   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  50.   " need to use a special type of cString: cCommentString, which also ends on
  51.   " "*/", and sees a "*" at the start of the line as comment again.
  52.   " Unfortunately this doesn't very well work for // type of comments :-(
  53.   syntax match cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  54.   syntax region cCommentString    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  55.   syntax region cComment2String    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  56.   syntax region cComment    start="/\*" end="\*/" contains=cTodo,cCommentString,cCharacter,cNumber,cFloat
  57.   syntax match  cComment    "//.*" contains=cTodo,cComment2String,cCharacter,cNumber
  58. else
  59.   syn region cComment        start="/\*" end="\*/" contains=cTodo
  60.   syn match cComment        "//.*" contains=cTodo
  61. endif
  62. syntax match cCommentError    "\*/"
  63.  
  64. syn keyword cOperator    sizeof
  65. syn keyword cType        int long short char void size_t
  66. syn keyword cType        signed unsigned float double
  67. syn keyword cStructure    struct union enum typedef
  68. syn keyword cStorageClass    static register auto volatile extern const
  69.  
  70. syn region cPreCondit    start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\|elif\>\|else\>\|endif\>\)" skip="\\$" end="$" contains=cComment,cString,cCharacter,cNumber,cCommentError
  71. syn region cIncluded contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  72. syn match cIncluded contained "<[^>]*>"
  73. syn match cInclude        "^\s*#\s*include\>\s*["<]" contains=cIncluded
  74. "syn match cLineSkip    "\\$"
  75. syn region cDefine        start="^\s*#\s*\(define\>\|undef\>\)" skip="\\$" end="$" contains=ALLBUT,cPreCondit,cIncluded,cInclude,cDefine,cInParen,cUserLabel
  76. syn region cPreProc        start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,cPreCondit,cIncluded,cInclude,cDefine,cInParen,cUserCont,cUserLabel
  77.  
  78. " Highlight User Labels
  79. syn region    cMulti        transparent start='?' end=':' contains=ALLBUT,cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
  80. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  81. syn match    cUserCont    "^\s*\I\i*\s*:$" contains=cUserLabel
  82. syn match    cUserCont    ";\s*\I\i*\s*:$" contains=cUserLabel
  83. syn match    cUserCont    "^\s*\I\i*\s*:[^:]" contains=cUserLabel
  84. syn match    cUserCont    ";\s*\I\i*\s*:[^:]" contains=cUserLabel
  85.  
  86. syn match    cUserLabel    "\I\i*" contained
  87.  
  88. " Avoid recognizing most bitfields as labels
  89. syn match    cBitField    "^\s*\I\i*\s*:\s*[1-9]"me=e-1
  90. syn match    cBitField    ";\s*\I\i*\s*:\s*[1-9]"me=e-1
  91.  
  92. if !exists("c_minlines")
  93.   let c_minlines = 10
  94. endif
  95. exec "syn sync ccomment cComment minlines=" . c_minlines
  96.  
  97. if !exists("did_c_syntax_inits")
  98.   let did_c_syntax_inits = 1
  99.   " The default methods for highlighting.  Can be overridden later
  100.   hi link cLabel    Label
  101.   hi link cUserLabel    Label
  102.   hi link cConditional    Conditional
  103.   hi link cRepeat    Repeat
  104.   hi link cCharacter    Character
  105.   hi link cSpecialCharacter cSpecial
  106.   hi link cNumber    Number
  107.   hi link cFloat    Float
  108.   hi link cOctalError    cError
  109.   hi link cParenError    cError
  110.   hi link cInParen    cError
  111.   hi link cCommentError    cError
  112.   hi link cOperator    Operator
  113.   hi link cStructure    Structure
  114.   hi link cStorageClass    StorageClass
  115.   hi link cInclude    Include
  116.   hi link cPreProc    PreProc
  117.   hi link cDefine    Macro
  118.   hi link cIncluded    cString
  119.   hi link cError    Error
  120.   hi link cStatement    Statement
  121.   hi link cPreCondit    PreCondit
  122.   hi link cType        Type
  123.   hi link cCommentError    cError
  124.   hi link cCommentString cString
  125.   hi link cComment2String cString
  126.   hi link cCommentSkip    cComment
  127.   hi link cString    String
  128.   hi link cComment    Comment
  129.   hi link cSpecial    SpecialChar
  130.   hi link cTodo        Todo
  131.   "hi link cIdentifier    Identifier
  132. endif
  133.  
  134. let b:current_syntax = "c"
  135.  
  136. " vim: ts=8
  137.